#!/bin/bash

MAINPATH="/var/www/aizhike"
AIBLOG="/var/www/aizhike/main.py"

[ -f $AIBLOG ] || exit 0

start() {
        echo -n "Starting aiblog: "
        spawn-fcgi -d ${MAINPATH} -f ${AIBLOG} -a 127.0.0.1 -p 9001
        echo "OK"
}

stop() {
        echo -n "Stopping aiblog: "
        kill -9 `pgrep -f "python ${AIBLOG}"`
        echo "OK"
}

restart() {
        stop
        start
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart|reload)
        restart
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart}"
        exit 1
esac

exit $?
